var Pass_updateModify = function () {
	
	
	var handleValidation1 = function() {
		var form1 = $('#submit_form');
        var error1 = $('.alert-danger', form1);
        var success1 = $('.alert-success', form1);
        
        /*******************密码判断 start***********************/
        $.validator.addMethod("isRight",function(value){
            var password_old = value;
            $.ajax({
                type:"POST",
                async:false, 
                url:"/pass_update/ajaxcheck/get",
                data:{password_old:password_old},
                success:function(response){
                    if(response ==0){
                        res = false;
                    }else{
                        res = true;
                    }
                }
            });
            return res;
        });
        $.validator.addMethod("isEqual",function(value){
        	
        	if($('#password').attr('value')==$('#password_again').attr('value'))
        		res=true;
        	else res=false;
        	return res;
        	
        });
        /*******************密码判断 end ***********************/
        
        form1.validate({
    		focusCleanup: true, //focus对应对象时隐藏错误提示
    		focusInvalid: false,//验证后让未通过验证的第一个表单元素获得焦点
    		errorClass: "help-block",
    		validClass: "valid-ok",
    		errorElement: "span",
    		submitHandler: function(form){ //当表单验证成功并提交时执行
    			  			        		
    			$(form).ajaxSubmit({
    				       				
    				  success: function(res) {
    					 a = JSON.parse(res);
    					 if(a.response.data){
     						msg = "修改成功";
     				         //bootbox.alert("修改成功！")       				         
     				        
     					 }else{
     						 msg = "修改失败！";
     						 //bootbox.alert("修改失败！"); 
     						      						
     					 } 
     					 
     					 bootbox.dialog({
			                    message: msg,
			                    title: "",
			                    buttons: {
			                      success: {
			                        label: "OK",
			                        className: "green",
			                        callback: function() {
				        	 			window.location.href = '/chart/lists/get';
			                        }
			                      }
			                    }
			                }); 					
    				    
    				  },
    					
    				  error: function (XmlHttpRequest, textStatus, errorThrown) {
    					  console.log(errorThrown);
    					},  
    			    url:'/pass_update/modifyresource/put', /*设置post提交到的页面*/  
    			    type: 'post', /*设置表单以post方法提交*/
    			    resetForm: false
    				});
    		},
    		rules: {
    		  password_old: {
    			  required: true,
    			  isRight: true
    				//minlength: 5
    		  },
    		  password: {
    			  required: true,
    				//minlength: 5
    		  },
    		  password_again: {
    			  required: true,
    			  isEqual:true
    				//minlength: 5
    		  }
    		},
    		messages: {
      		  password_old: {
  			  required: "请填写原密码",
  			  isRight: "输入原密码不正确"
  		  },
  		  password: {
  			  required: "请填写新密码",
  		  },
  		  password_again: {
  			  required: "请再次填写新密码",
  			  isEqual:"二次密码输入不正确"
  		  }
  		},
    		invalidHandler: function (event, validator) { //display error alert on form submit              
    			success1.hide();
                error1.show();
                App.scrollTo(error1, -200);
            },

            highlight: function (element) { // hightlight error inputs
                $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
            },

            unhighlight: function (element) { // revert the change done by hightlight
                $(element)
                    .closest('.form-group').removeClass('has-error'); // set error class to the control group
            },

            success: function (label) {
                label
                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
            }
    		
    	});
	}
		
    	
		
		
		
		
	var cancelButton = function() {
		$('#cancel').click(function() {
			window.location.href = '/chart/lists/get';
		});

	}
		
		
    return {
        //main function to initiate the module

        init: function () {
    	
    		handleValidation1();
    		cancelButton();
        }
    };

}();